<?php
/**
* @version		$Id: view.html.php 
* @package		Joomla
* @subpackage	Clickdesk
* @license		GNU/GPL, see LICENSE.php
* Joomla! is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
*/

// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );

jimport( 'joomla.application.component.view');

/**
 * HTML View class for the Geo component
 *
 * @static
 * @package		Joomla
 * @subpackage	Clickdesk
 * @since 1.0
 */
class ClickdeskViewClickdesk extends JView
{
        var $clickdesk  = "";

	function display($tpl = null)
	{
		global $mainframe;

		$db		=& JFactory::getDBO();
		$user 	=& JFactory::getUser();
 
		$query = "select * from #__clickdesk limit 1";

		$options = array();

		$db->setQuery($query);
		$options["clickdesk_id"] = 0;
		$options["clickdesk_widget"] = "";


		define('LIVILY_SERVER_URL', "http://wp-1.contactuswidget.appspot.com/");
		define('LIVILY_DASHBOARD_URL', LIVILY_SERVER_URL.'widgets.jsp?cdplugin=joomla&wpurl=');

 

		$Path="http://".$_SERVER['HTTP_HOST']."/".$_SERVER['REQUEST_URI'];

		$Path = urlencode($Path);

		$cdURL= LIVILY_DASHBOARD_URL.$Path;


 



		if($result = $db->query())
		{
			$rows = $db->getNumRows();
			if($rows != 0)
			{
				$clickdesk_data = $db->loadAssocList();

				$options["clickdesk_id"] = $clickdesk_data[0]["id"];
				$options["clickdesk_widget"] = $clickdesk_data[0]["widget_id"];


			}

		} 

		if(strlen($options["clickdesk_widget"]) != 0){
			$mssg = urlencode("Plugin has been installed successfully.");
			$cdURL = $cdURL."&mssg=".$mssg;

			$options["cdurl"] = $cdURL;

		}else
		{

			$options["cdurl"] = $cdURL;	

		}
 

 
		$this->assignRef('options',	$options);

		parent::display($tpl);

	}

 
}
